﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Game.model;
using java.util;
using ArrayList = java.util.ArrayList;

namespace Game.ai
{
    public class RaceManager:DefaultAI
{
	/**
	 * Field thinking.
	 */
	private bool thinking = false;
	/**
	 * Field _knownPlayers.
	 */
	private List _knownPlayers = new ArrayList();
	
	/**
	 * Constructor for RaceManager.
	 * @param actor NpcInstance
	 */
	public RaceManager(NpcInstance actor):base(actor)
	{
		//super(actor);
		AI_TASK_ATTACK_DELAY = 5000;
	}
	
	/**
	 * Method runImpl.
	 */
	
	public override void runImpl()
	{
		onEvtThink();
	}
	
	/**
	 * Method onEvtThink.
	 */
	
	protected override void onEvtThink()
	{
		RaceManagerInstance actor = getActor();
		if (actor == null)
		{
			return;
		}
		MonRaceInfo packet = actor.getPacket();
		if (packet == null)
		{
			return;
		}
		lock(this)
		{
			if (thinking)
			{
				return;
			}
			thinking = true;
		}
		try
		{
			List newPlayers = new ArrayList();
			foreach (Player player in World.getAroundPlayers(actor, 1200, 200))
			{
				if (player == null)
				{
					continue;
				}
				newPlayers.add(player);
				if (!_knownPlayers.contains(player))
				{
					player.sendPacket(packet);
				}
				_knownPlayers.remove(player);
			}
			foreach (Player player in (IEnumerable)_knownPlayers)
			{
				actor.removeKnownPlayer(player);
			}
			_knownPlayers = newPlayers;
		}
		finally
		{
			thinking = false;
		}
	}
	
	/**
	 * Method getActor.
	 * @return RaceManagerInstance
	 */
	
	public override RaceManagerInstance getActor()
	{
		return (RaceManagerInstance) base.getActor();
	}
}

}
